Ext.BLANK_IMAGE_URL = '/govdomain/extjs/resources/images/default/s.gif';
Ext.QuickTips.init();
var start = {
	id : 'start-panel',
	title : '欢迎使用',
	layout : 'fit',
	bodyStyle : 'padding:25px',
	html : '<img src="/govdomain/images/bg.jpg"/>'
};


Ext.onReady(function() {
	setTimeout(function() {
		Ext.get('loading').remove();
		Ext.getDom('header').style.visibility = 'visible';
		var tree=new Ext.tree.AsyncTreeNode({id : "root"});
		var yearAddMenuContext = new Ext.menu.Menu({
						items : [
							{text:'添加年度',iconCls:'icon-add',handler:addHanlder}
						]
		});
		var yearMenuContext = new Ext.menu.Menu({
						items : [
							{text:'删除年度',iconCls:'icon-delete',handler:addHanlder},
							{text:'添加期刊',iconCls:'icon-add',handler:addHanlder}
						]
		});
		var periodMenuContext = new Ext.menu.Menu({
						items : [
							{text:'删除期刊',iconCls:'icon-delete',handler:deleteHanlder}
						]
		});
		function addHanlder(n){
			alert(n.id);
		};
		function deleteHanlder(){
		
		};
		var vp = new Ext.Viewport({
			layout : 'border',
			defaults : {
				collapsible : true,
				split : true
			},
			items : [{
				xtype : 'box',
				region : 'north',
				applyTo : 'header',
				height : 30,
				split : false
			}, {
				title : currentUser,
				id : 'accordion-panel',
				layout : 'border',
				region : 'west',
				margins : '2 0 5 5',
				width : 200,
				minSize : 200,
				maxSize : 250,
				bodyStyle : 'background-color:#DFE8F6',
				defaults : {
					border : false
				},
				 tbar: [{
				            iconCls:'icon-add',
				            text:'添加年度',
				            handler: this.showWindow,
				            scope: this
				        },{
				            id:'delete',
				            iconCls:'icon-del',
				            text:'Remove',
				            handler: function(){
				                var s = this.getSelectionModel().getSelectedNode();
				                if(s){
				                    this.removeFeed(s.attributes.url);
				                }
				            },
				            scope: this
				        },{
				            iconCls:'icon-add',
				            text:'添加',
				            handler: this.showWindow,
				            scope: this
				        },{
				            id:'delete',
				            iconCls:'icon-del',
				            text:'Remove',
				            handler: function(){
				                var s = this.getSelectionModel().getSelectedNode();
				                if(s){
				                    this.removeFeed(s.attributes.url);
				                }
				            },
				            scope: this
				        }
				        ]
				,
				bbar : [{
					text : '开始',
					iconCls : 'icon-plugin',
					menu : new Ext.menu.Menu({
						items : [{
							text : '关于系统',
							iconCls : 'icon-info',
							handler : function() {
								new Ext.Window({
									closeAction : 'close',
									resizable : false,
									bodyStyle : 'padding: 7',
									modal : true,
									title : '关于本系统',
									html : '本系统采用目前较为流行的技术实现,保证了数据在通信网络中的快速传输，感谢辉辉同学的技术投入！',
									width : 300,
									height : 200
								}).show();
							}
						}, {
							text : '退出系统',
							iconCls : 'icon-delete',
							handler : function() {
								Ext.Msg.confirm('操作提示', '您确定要退出本系统?', function(btn) {
									if ('yes' == btn) {
										Ext.Ajax.request({
											url : 'useraction.do?method=logout',
											success : function() {
												location = '/govdomain/index.jsp';
											},
											failure : function() {
												Ext.Msg.show({
													title : '错误提示',
													msg : '退出系统失败!',
													icon : Ext.Msg.ERROR,
													buttons : Ext.Msg.OK
												});
											}
										});
									}
								});
							}
						}]
					})
				}],
				items : [{
					layout : 'accordion',
					region : 'center',
					items : [{
						title : '导航菜单',
						iconCls : 'icon-nav',
						border : false,
						items : [{
							xtype : 'treepanel',
							border : false,
							rootVisible : false,
							autoScroll : true,
							root : tree,
							listeners : {
								'beforeload' : function(node) {
									node.loader=new Ext.tree.TreeLoader({
										url : "viewaction.do?method=queryTreeNodes&id="+node.id
									})
								},
								'click' : function(n) {
									try {
										var sn = this.selModel.selNode || {};
										if (n.leaf && n.id != sn.id) {
											Ext.getCmp('content-panel').layout.setActiveItem(n.id.substring(0, n.id
													.indexOf('-'))
													+ '-panel');
											var store = grid_article.getStore();
											store.baseParams.periodId=n.id.substring(n.id.indexOf('-')+1,n.id.indexOf('_'));
											store.load();
											grid_article.render();
											selectNodeId=n.id.substring(n.id.indexOf('_')+1);
											selectNodeYear=n.text.substring(0,n.text.indexOf('-'));
											selectNodePeriodId=n.id.substring(n.id.indexOf('-')+1,n.id.indexOf('_'));
										}
									} catch (e) {
										alert(e.message);
									}
								},
								'contextmenu' : function(n){
									n.select();
									nodeid=n.id;
									if (nodeid=="1"){
										yearAddMenuContext.show(n.ui.getAnchor());
									}
									if (nodeid.substring(0, nodeid.indexOf('-')) =="year") {
										yearMenuContext.show(n.ui.getAnchor());
									}
									if (nodeid.substring(0, nodeid.indexOf('-')) =="article") {
										periodMenuContext.show(n.ui.getAnchor());
									}
								}
							}
						}]
					}]
				}]
			}, {
				id : 'content-panel',
				region : 'center',
				layout : 'card',
				margins : '2 5 5 0',
				activeItem : 0,
				border : false,
				items : [start,p_article]
			}]
		});
	}, 250);
});
